package ml.coursedesign.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ml.coursedesign.entity.Course;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

/**
 * Mapper 接口
 *
 * @author likeqc.top
 * @since 2021-04-27
 */
public interface CourseMapper extends BaseMapper<Course> {

  /**
   * 聚合查询课程信息（课程名，学时，学分，班级数，选课总人数，授课教师）
   * @param page
   * @return
   */
  @Select("SELECT c.id, c.`name` courseName, c.`hours`, c.`credit`, COUNT(DISTINCT cc.`classNum`) classCount, COUNT(sc.`course_class_id`) studentCount, GROUP_CONCAT(DISTINCT t.nickname) teachers FROM course c LEFT JOIN course_class cc ON c.id=cc.`course_id` LEFT JOIN teacher t ON cc.`teacher_id`=t.id LEFT JOIN select_course sc ON cc.`id`=sc.course_class_id GROUP BY c.`name` ")
  IPage<Map> getList(Page page);
}
